package com.example.pages;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

public class MovieAddPage extends InternalPage{

    @FindBy(name = "imdbid")
    public WebElement numberIMDBField;

    @FindBy(name = "name")
    public WebElement nameMovieField;

    @FindBy(name = "aka")
    public WebElement aboutMovie;

    @FindBy(name = "year")
    public WebElement yearMovie;

    @FindBy(name = "duration")
    public WebElement durationMovie;

    @FindBy(name = "rating")
    public WebElement ratingMovie;

    @FindBy(id = "text_languages_0")
    public WebElement languagesMovie;

    @FindBy(name = "subtitles")
    public WebElement subtitlesMovie;

    @FindBy(name = "submit")
    public WebElement saveButton;

    @FindBy(xpath = "//h2[text() = 'Movie information']")
    public WebElement titlePageAddMovie;

    public boolean isOnThisPage(){
        return titlePageAddMovie. isDisplayed();
    }

    @Override
    void tryToOpen(){
        MyPageFactory.getPage(driver, LoginPage.class)
            .loginWithValidCredentials("admin", "admin")
            .gotoHomePage()
            .addNewMovie();
    }

    public MoviePage sendAddForm(String imdbid, String name, String info, String date, String time, String rating, String text) {
        numberIMDBField.sendKeys(imdbid);
        nameMovieField.sendKeys(name);
        aboutMovie.sendKeys(info);
        yearMovie.sendKeys(date);
        durationMovie.sendKeys(time);
        ratingMovie.sendKeys(rating);
        languagesMovie.sendKeys(text);
        subtitlesMovie.sendKeys(text);
        saveButton.click();
        return MyPageFactory.getPage(driver, MoviePage.class);
    }
}
